from functools import cache


class Solution:

    def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:
        if y >= x:
            return y - x
        f = [-1] * (x * 11)
        f[y] = 0
        l = [y]

        def p(c, num):
            if num < len(f) and num > -1 and f[num] == -1:
                f[num] = f[c] + 1
                l.append(num)

        while l:
            c = l.pop(0)
            if c * 11 == x or c * 5 == x or c + 1 == x or c - 1 == x:
                return f[c] + 1
            p(c, c + 1)
            p(c, c - 1)
            p(c, c * 5)
            p(c, c * 11)


class Solution:

    def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:

        @cache
        def f(x, y):
            print(x,y)
            if y >= x:
                return y - x
            ans = min(f(x + 1, y), f(x - 1, y)) + 1
            if x % 11 == 0:
                ans = min(ans, f(x // 11, y) + 1)
            if x % 5 == 0:
                ans = min(ans, f(x // 5, y) + 1)
            return ans

        return f(x, y)


s = Solution()
print(s.minimumOperationsToMakeEqual(x=26, y=1))
